package com.zhongyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.GoodsMapper;
import com.zhongyu.pojo.Goods;
import com.zhongyu.pojo.User;
import com.zhongyu.service.GoodsService;
import com.zhongyu.vo.GoodsVo;
import com.zhongyu.vo.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
@Service("GoodsService")
public class GoodsServicelmpl  extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Resource
    private GoodsMapper goodsMapper;
    @Override
    public PageResult searchAll(Integer pageNo, Integer pageSize, GoodsVo goodsVo) {
        LambdaQueryWrapper<Goods> wrapper= Wrappers.<Goods>lambdaQuery();
        wrapper.like(!StringUtils.isEmpty(goodsVo.getName()),Goods::getName,goodsVo.getName())
                .eq(goodsVo.getGoodsTypeid()!=null,Goods::getGoodsTypeid,goodsVo.getGoodsTypeid())
                .ge(goodsVo.getStartDate()!=null,Goods::getCreationDate,goodsVo.getStartDate())
                .le(goodsVo.getEndDate()!=null,Goods::getCreationDate,goodsVo.getEndDate());
        Page page=new Page(pageNo,pageSize);
        List<Goods> list=baseMapper.findAll(page,wrapper);
        return new PageResult(list,page.getTotal());
    }

    @Override
    public List<Goods> searchAll() {
        return goodsMapper.selectList(null);
    }

    @Override
    public Goods searchById(Integer id) {
        return goodsMapper.findById(id);
    }

    @Override
    public List<Goods> searchByName(String name) {
        return goodsMapper.findByName(name);
    }

    @Override
    public List<Goods> searchByCode(String code) {
        return goodsMapper.findByCode(code);
    }

    @Override
    public void add(Goods goods) {
        goodsMapper.insert(goods);
    }

    @Override
    public void del(Integer id) {
 goodsMapper.deleteById(id);
    }

    @Override
    public void update(Goods goods) {
goodsMapper.updateById(goods);
    }

    @Override
    public List<Goods> searchId(Integer providerId) {
        return goodsMapper.findId(providerId);
    }
}
